/**
 * Created by mkDark on 2018/3/20.
 */
var moment = require('moment');
var async = require('async');
var superagent = require('superagent');
var CONFIG = require('../../../../common/config');
var CODE = require('../../../../common/code');
var ItbQaTmplModel = require('../../../../common/mysql/mapping/ItbQaTmplModel');
var ItbQaInfoModel = require('../../../../common/mysql/mapping/ItbQaInfoModel');
var YjxActivityModel = require('../../../../common/yjxMysql/mapping/YjxActivityModel');
var YjxActRewardRuleModel = require('../../../../common/yjxMysql/mapping/YjxActRewardRuleModel');
var YjxActUserProductModel = require('../../../../common/yjxMysql/mapping/YjxActUserProductModel');
var retUtil = require('./retUtil');
var YjxOrgRModel = require('../../../../common/yjxMysql/mapping/YjxOrgRModel');
var YjxCouponModel = require('../../../../common/yjxMysql/mapping/YjxCouponModel');
var activityServiceUtil = require('../../../service/serviceUtil/activityServiceUtil');
var luaUtil = require('./luaUtil');

var activityUtil = (function () {

    function activityUtil() {

    }

    /**
     * 获取问卷调查数据模板
     *
     * @author 毛凯
     * @date 2018-3-20
     *
     * @param   id 问卷调查模板 id(页面写死)
     * @param   callback 回调
     *             err:出错原因
     *             res:返回问卷内容
     * */
    activityUtil.getQaTmpl = function(id,callback){

        var entity = new ItbQaTmplModel({
            qa_id : id,
            del_flg : 0
        });
        //获取问卷调查数据模板
        entity.findFromDB(function(err,res){
            if(err){
                return callback(err, null);
            }
            if(!res || res.length <=0){
                return callback(null, {});
            }
            var data = {};
            data.id = res[0].qa_id;
            data.title = res[0].title;

            var res = retUtil.safe_parser_JSON_string(res[0].data);
            if(!res){
                data.questions = {};
                return callback(err, data);
            }
            data.questions = res.questions;
            return callback(err, data);
        });
    };

    /**
     * 提交问卷调查数据模板
     *
     * @author 毛凯
     * @date 2018-3-20
     *
     * @param   answer 问卷调查回复 answer
     * @param   callback 回调
     *             err:出错原因
     *             res:成功
     * */
    activityUtil.commitQaAnswer = function(answer,callback){

        var answer = retUtil.safe_parser_JSON_string(answer);
        if(!answer){
            return callback("answer参数有误", null);
        }
        var entity = new ItbQaInfoModel({
            qa_id : answer.id || 1,
            user_id :answer.user_id || "",
            mobile :answer.mobile || "",
            mail :answer.mail || "",
            qq :answer.qq || "",
            addr :answer.addr || "",
            desc :answer.desc || "",
            data : JSON.stringify(answer.data)||"",
            update_by : answer.user_id || ""
        });
        //存放到数据库中
        entity.saveToDB(function(err,res){
            if(err){
                return callback(err, null);
            }
            return callback(err, {});
        });
    };

    /**
     * 活动活动列表
     *
     * @author 毛凯
     * @date 2018-6-8
     *
     * @param {Object}  param 筛选活动的参数列表
     * @param {Array}  param.states    活动状态数组10未开场、20已开场、30活动截止、40活动关闭、50活动取消 数组的json字符串
     * @param {Number} param.pageNum   页码
     * @param {Number} param.pageSize  页容量
     * @param {Number} [param.userId]  用户id
     * @param {Number} [param.filterUser] 是否根据用户过滤活动列表, 0 不过滤, 1 过滤, 如使用该字段必须传递 userId
     * @param {Number} [param.checkReward] 是否检测用户在活动中的获奖状况,0 不过滤, 1 过滤,  如使用该字段必须传递 userId
     * @param {Number} param.withTotalPage 是否需要返回总页数  0不需要  1需要
     * @param {Number} param.orgId 组织id该接口不适用该参数
     * @param {Number} param.flag 用来标记当前接口需要使用publish字段
     * @param callback {}
     * */
    activityUtil.getActivityList_v1_7 = function(param,callback){
        var totalTasks = [];
        var entity = new YjxActivityModel();
        //获取活动列表有用户id无用户id
        totalTasks.push(function (callback) {
            var data = {};
            entity.getActivityList(param,function(err,result) {
                if (err){
                    return callback(err, null);
                }
                data.activitys = result;
                return callback(null,data);
            });
        });
        //处理数据
        totalTasks.push(function (data,callback) {
            var list = [];
            if(!data.activitys || data.activitys.length <= 0){
                data.list = list;
                return callback(null,data);
            }
            list = data.activitys;
            data.list = list;
            return callback(null,data);
        });
        //有用户id的情况计算用户的参加每个活动的总共获奖作品数和获奖的奖金总金额
        totalTasks.push(function (data,callback) {
            if (!param.userId || !param.checkReward ){
                return callback(null,data);
            }
            if (!data.list || data.list.length <= 0){
                return callback(null,data);
            }

            var tasks = [];
            for(var i=0; i<data.list.length; i++ ) {
                var t = (function(act){
                    return function (ck) {
                        var actId = act.id;
                        entity.getUserRewardCntAndUserDoc(actId,param.userId,function (err,result) {
                            if (result && result.length>0){
                                act.rewardProductCnt = result[0].rewardProductCnt || 0;
                                act.totalRewardAmount = result[0].totalRewardAmount || 0;
                                return ck(null,result);
                            }else{
                                return ck(null,null);
                            }
                        });
                    }
                })(data.list[i]);
                if(tasks){tasks.push(t)};
            }
            async.parallel(tasks, function(error, tasksResults){
                if (error) {
                    return callback(error,null);
                }
                return callback(null,data);
            });
        });
        //分页计算
        totalTasks.push(function (data,callback) {
            if (!param.withTotalPage){
                return callback(null,data);
            }
            entity.getActivityListCnt(param,function (err,count) {
                data.totalPage = Math.floor((count-1)/param.pageSize)+1 || 0;
                return callback(null,data);
            });
        });
        // 顺序执行
        async.waterfall(totalTasks, function (activityErr, data) {
            if(activityErr) {
                return callback(activityErr, null);
            }
            if (!param.withTotalPage){
                return callback(activityErr,{list:data.list});
            }else{
                return callback(activityErr,{list:data.list,currentPage:param.pageNum,totalPage:data.totalPage});
            }
        });
    };

    /**
     * 获取活动详情信息
     *
     * @author 王俊
     * @date 2018-06-08
     *
     * @deprecated 请使用 Service/activityService/getActivityDetail 方法, 2018-07-24 王俊
     *
     * @param {Object} options   请求参数
     * @param {Number} options.device       设备类型, 参考接口定义
     * @param {Number} options.activityId   活动唯一标识
     * @param {Number} options.topLimit     排行限制
     * @param {Function} callback 回调函数
     *                      error: 查询出错
     *                      data : 结构复杂, 参考 接口 http://yapi.yijianxiu.com:7000/project/11/interface/api/3388
     */
    activityUtil.getActivityDetail_v1_7 = function (options, callback) {

        var totalTasks = [];

        // 1. 获取活动信息
        totalTasks.push(function (callback) {

            activityUtil.getSingleActivityDetailInfoById(options.activityId, function (error, activity) {
                var data = {};
                data.activity = activity;
                return callback(error, data);
            });
        });
        // 2. 获取活动统计信息
        totalTasks.push(function (data, callback) {
            var entity = new YjxActivityModel();
            entity.getActivityStatisticsInfo({activityId : options.activityId}, function (error, info) {
                data.statisticsInfo = info;
                // 注意: 此处应根据参与平台类型来决定 totalData1 与 totalData2 对应字段, 暂不处理
                data.statisticsInfo.totalLike = info.totalData1 || 0;
                data.statisticsInfo.totalComment = info.totalData2 || 0;
                delete data.statisticsInfo.totalData1;
                delete data.statisticsInfo.totalData2;
                return callback(error, data);
            });
        });
        // 3. 获取活动排行表
        totalTasks.push(function (data, callback) {
            var entity = new YjxActUserProductModel();
            var opt = {
                activityId : options.activityId,
                pageNum : 0,
                pageSize : options.topLimit
            };
            entity.getActivityProductList(opt, function (error, products) {
                data.products = products;
                return callback(error, data);
            });
        });
        // 4. 重组数据
        totalTasks.push(function (data, callback) {
            data.retData = {};
            data.retData.activity = data.activity;
            data.retData.brief = data.statisticsInfo;
            data.retData.topProducts = [];

            for (var i=0; i < data.products.length; i ++) {
                var p = data.products[i];

                data.retData.topProducts.push({
                    id : p.aup_id,
                    thumb : p.theme_img_cust || p.theme_img,
                    url : p.url,
                    video : p.video,
                    state : p.state,
                    note : p.note,
                    rewardAmount : p.reward_amt,
                    unit : p.unit,
                });
                // 抖音
                if(p.platform_type === 10) {
                    data.retData.topProducts[i].like = Number(p.data1);
                    data.retData.topProducts[i].comment = Number(p.data2);
                }
            }
            return callback(null, data);
        });
        // 5. redis记录活动的浏览次数
        totalTasks.push(function (data, callback) {
            luaUtil.statisticsActivityInfo(options.activityId,function (err,result) {
                if (err || result){
                    console.log(err || "lua存储活动信息失败:"+err);
                    return callback(null,data);
                }
                return callback(null,data);
            });
        });
        async.waterfall(totalTasks, function (error, data) {
            if(error) {
                return callback(error, null);
            }
            return callback(error, data.retData);
        });
    };

    /**
     * 根据活动 id 查询单个活动详细信息
     *
     * @author 王俊
     * @date 2018-06-08
     *
     * @param {Number} activityId 活动 id
     * @param {Function} callback 回调函数
     *                      error: 获取失败
     *                      data : 活动基础信息 + 活动规则信息
     */
    activityUtil.getSingleActivityDetailInfoById = function (activityId, callback) {
        var totalTasks = [];

        // 1. 基础信息
        totalTasks.push(function (callback) {

            var entity = new YjxActivityModel();
            entity.getSingleActivitySettingInfo(activityId, function (error, actInfo) {
                 var data = {};
                 data.actInfo = actInfo;

                 // 筹备中
                 if(data.actInfo && data.actInfo.state === 60) {
                    return callback('大赛筹备中, 敬请期待', null);
                 }
                 return callback(error, data);
            });
        });
        // 2. 获取规则信息
        totalTasks.push(function (data, callback) {
            var entity = new YjxActRewardRuleModel({
                as_id : data.actInfo.as_id,
                type :  10, //10为实际的奖励，20为推荐码奖励
                state : 10, // 10 有效
                del_flg : 0
            });
            entity.getOrderBy = function () {return ' `min` ';};
            entity.findFromDB(function (error, rules) {
                if(error || !rules || rules.length <=0) {
                    return callback(error||'该活动状态异常', null);
                }
                data.rules = rules;
                return callback(error, data);
            });
        });
        // 3. 重组活动信息
        totalTasks.push(function (data, callback) {
            data.retData = {};

            data.retData.id = data.actInfo.act_id;
            data.retData.state = data.actInfo.state; // 默认为 10
            data.retData.thumb = data.actInfo.theme_img;
            data.retData.url = data.actInfo.url;
            data.retData.title = data.actInfo.title;
            data.retData.startDate = data.actInfo.startDate;
            data.retData.endDate = data.actInfo.endDate;
            data.retData.startTimestamp = data.actInfo.startTimestamp;
            data.retData.endTimestamp = data.actInfo.endTimestamp;

            data.retData.type = data.actInfo.type;
            data.retData.platformType = data.actInfo.platform_type;
            data.retData.images = retUtil.safe_parser_JSON_string(data.actInfo.images) || [];
            data.retData.orgName = data.actInfo.org_name;
            data.retData.productLimit = data.actInfo.product_limit;
            data.retData.rewardTotal = data.actInfo.reward_total;

            return callback(null,data);
        });

        // 4. 拼接奖励规则
        totalTasks.push(function (data, callback) {
            var rewardRule = '';
            for (var i=0; i< data.rules.length; i++) {
                var r = data.rules[i];
                if(r.min === r.max) {
                    rewardRule += '第'+r.min + '名获得 ' + r.reward_amt/100 + ' 元';
                } else {
                    rewardRule += r.min + '-' + r.max + '名每人获得 ' + r.reward_amt/100 + '元';
                }
                rewardRule += i === data.rules.length-1 ? '。' : '；\n';
            }
            var rule = '在短视频平台中';
            var condition = '挑战者根据拍摄要求在短视频平台获得至少获得';
            if(data.actInfo.field1) {
                rule += '每';
                // 抖音
                if(data.actInfo.platform_type === 10) {
                    if(data.actInfo.threshold1 > 0) {
                        condition += data.actInfo.threshold1 + '点赞、';
                    }
                    rule += '赞'
                }
                // 其他平台配置
                else {
                    if(data.actInfo.threshold1 > 0) {
                        condition += data.actInfo.threshold1 + '点赞、';
                    }
                    rule += '赞'
                }
                rule += '得' + data.actInfo.weight1 + '分、';
            }
            if(data.actInfo.field2) {
                rule += '每';
                // 抖音
                if(data.actInfo.platform_type === 10) {
                    if(data.actInfo.threshold2 > 0) {
                        condition += data.actInfo.threshold2 + '评论、';
                    }
                    rule += '评论'
                }
                // 其他平台配置
                else {
                    if(data.actInfo.threshold2 > 0) {
                        condition += data.actInfo.threshold2 + '评论、';
                    }
                    rule += '评论'
                }
                rule += '得' + data.actInfo.weight2 + '分、';
            }
            if(condition.length > 21) {
                condition = condition.substr(0, condition.length -1);
                condition += '才能参与评奖';
            }
            rule = rule.substr(0, rule.length -1);
            rule += '，总分越高排名越靠前';

            data.retData.introduce = [
                {title : '主办方', content : data.actInfo.org_name},
                {title : '挑战名称', content : data.actInfo.title},
                {title : '挑战日期', content : data.actInfo.startDate + '-' + data.actInfo.endDate},
                {title : '奖金总额', content : data.actInfo.reward_total/100 + '元'},
                {title : '奖励分配', content : rewardRule},
                {title : '获奖条件', content : condition},
                {title : '挑战上限', content : '每个账号最多'+data.actInfo.product_limit+'个作品'},
                {title : '评分规则', content : rule},
                {title : '挑战描述', content : data.actInfo.desc}
            ];
            // 没有门槛, 移除参与条件
            if(condition.length <= 2) {
                data.retData.introduce.splice(5, 1);
            }
            return callback(null, data);
        });

        async.waterfall(totalTasks, function (error, data) {
            if(error) {
                return callback(error, null);
            }
            return callback(error, data.retData);
        });
    };

    /**
     * 获取用户参与活动信息
     *
     * @author 王俊
     * @date 2018-06-09
     *
     * @param {Object}options
     * @param {Number}options.device 设备标识
     * @param {Number}options.activityId 活动标识
     * @param {Number}options.userId 用户标识
     * @param {Function} callback 回调函数
     */
    activityUtil.getUserActivityInfo_v1_7 = function (options, callback) {

        var totalTasks = [];

        // 1. 查询活动信息
        totalTasks.push(function (callback) {
            activityServiceUtil.getSingleActivityDetailInfoById(options.activityId, function (error, actInfo) {
                var data = {};
                data.actInfo = actInfo;
                return callback(error, data);
            })
        });
        // 2. 查询用户作品信息
        totalTasks.push(function (data, callback) {
            var entity = new YjxActUserProductModel();
            var opt = {
                activityId : options.activityId,
                pageNum : 0,
                pageSize : data.actInfo.productLimit,
                userId : options.userId
            };
            entity.getActivityProductList(opt, function (error, products) {
                data.products = products;
                return callback(error, data);
            });
        });
        // 3. 重组数据
        totalTasks.push(function (data, callback) {
            data.retData = {};
            data.retData.activity = data.actInfo;
            data.retData.userRewardTotal = 0;
            data.retData.products = [];

            for (var i=0; i < data.products.length; i ++) {
                var p = data.products[i];
                data.retData.products.push({
                    id : p.aup_id,
                    thumb : p.theme_img_cust || p.theme_img,
                    url : p.url,
                    video : p.video,
                    state : p.state,
                    note : p.note,
                    rewardAmount : p.reward_amt,
                    unit : p.unit,
                    runk : p.runk
                });
                // 抖音
                if(p.platform_type === 10) {
                    data.retData.products[i].like = Number(p.data1);
                    data.retData.products[i].comment = Number(p.data2);
                }
                data.retData.userRewardTotal += Number(p.reward_amt||0);
            }
            return callback(null,data);
        });
        // 流式执行
        async.waterfall(totalTasks, function (error, data) {
            if(error) {
                return callback(error, null);
            }
            return callback(error, data.retData);
        })


    };


    /**
     * 个人参与活动_APP_1_7添加_M
     *
     * @author jackLiu
     * @date   2018-6-8
     *
     * @param device   提交作品的平台
     * @param activityId   活动唯一标识，例如：1298
     * @param userId   用户唯一标识，例如：299188
     * @param desc  用户对作品简要说明,
     * @param url  用户参赛的第三方链接，例如：https://xxx.xxx.com/xxx.mp4
     * @param couponCode 非必须  活动的推荐码
     * @param   callback 回调
     *             err:出错原因
     * */
    activityUtil.submitProduct_v1_7 = function(device,activityId, userId, desc, url,couponCode, callback){

        var totalTasks = [];
        // 验证推荐码
        totalTasks.push(function (callback) {
            var data = {};
            if(couponCode){
                (new YjxCouponModel()).checkCcode(couponCode,function (err,result) {
                    if(err){
                        return callback(err,null);
                    }
                    if (!result || !result[0] || !result[0].c_code){
                        return callback("邀请码错误！",null);
                    }else{
                        data.use = result[0].use;
                        return callback(null,data);
                    }
                });
            }else{
                return callback(null, data);
            }
        });
        // 检测活动状态
        totalTasks.push(function (data, callback) {
            var entity = new YjxActivityModel({
                act_id: activityId,
                del_flg:0
            });
            entity.findFromDB(function (error, results) {
                if(error || !results || results.length <=0) {
                    return callback(error || '该活动不存在或已结束', null);
                }
                var act = results[0];
                if (act.state > 30) {
                    return callback('活动已截止, 无法参与', null);
                }

                const current = moment();
                if(current.isBefore(act.start_time)) {
                    return callback('活动尚未开始, 无法参与', null);
                }
                if(current.isAfter(act.end_time)) {
                    return callback('活动已截止, 无法参与', null);
                }
                return callback(error, data);
            });
        });
        // 1. 声明模型
        totalTasks.push(function (data, callback) {
            // 提取url的关键部分
            var k = activityUtil.getKeyValueOfUrl(url);
            var  entity = new YjxActUserProductModel({
                device : device,
                user_id:userId,
                act_id:activityId,
                type:10,
                unit:'分',
                url:url,
                tag:k,
                state:20, /*审核中*/
                desc:desc,
                c_code: couponCode
            });
            data.productEntity = entity;
            return callback(null, data);
        });
        // 2. 排重链接
        totalTasks.push(function (data, callback) {
            data.productEntity.haveSameProduct(function(error, repetition) {
                if (error) {
                    return callback(error);
                }
                if (Number(repetition) === 1) {
                    return callback(CODE.YJX_ACTIVITY_FAIL_SAME_PRODUCT);
                }
                return callback(error, data);
            });
        });
        // 3. 上限值判断
        totalTasks.push(function (data, callback) {
            data.productEntity.reachProductCountLimit(function(error, reachLimit){
                if(error){
                    return callback(error);
                }
                if(Number(reachLimit)===1){
                    return callback(CODE.YJX_ACTIVITY_FAIL_REACH_PRODUCT_LIIT);
                }
                return callback(error, data);
            });
        });
        // 4. 获取公司信息
        totalTasks.push(function (data, callback) {
            // 获取用户所在的合作公司的信息
            var entity2 = new YjxOrgRModel();
            entity2.getUserPartnerOrgInfo(userId, function(error, org){
                if(error){
                    return callback(error);
                }

                if(org &&org.length>0 && org[0].id && data.use !== 20){
                    data.productEntity.org_id = org[0].id;
                }
                return callback(error, data);
            });
        });
        // 5. 存入 db
        totalTasks.push(function (data, callback) {
            data.productEntity.saveToDB(function (error, aupId) {
                data.aupId = aupId;
                if (CONFIG.DEBUG === 1) console.log('new user product: ' + aupId);
                return callback(error, data);
            });
        });

        // 6. 爬取数据并更新至 db
        totalTasks.push(function (data, callback) {
            var url = 'http://127.0.0.1:3000' + '/yjx/v1/api4back/api4back/updateDouyinDataOfActivityProduct';
            // var url = 'http://114.55.29.218:3000' + '/yjx/v1/api4back/api4back/updateDouyinDataOfActivityProduct';
            var para = {
                activityId : activityId,
                productIds : '[' + data.aupId + ']'
            };
            superagent.get(url)
                .send(para)
                .end(function (error, res) {

                    if(error) {
                        console.log('update product '+data.aupId+' error : ' + error);
                    }
                    if(res) {
                        console.log('request res: ' + res.text)
                    }
                });
            return callback(null, data);
        });
        async.waterfall(totalTasks, function (error, data) {
            return callback(error, {});
        });
    };

    /**
     * 后台手动上传作品用
     * @param activityId
     * @param userId
     * @param desc
     * @param url
     * @param couponCode
     * @param callback
     */
    activityUtil.submitProduct4Back_v1_7 = function(param, callback){

        var totalTasks = [];
        // 验证推荐码
        totalTasks.push(function (callback) {
            var data = {};
            if(param.couponCode){
                (new YjxCouponModel()).checkCcode(param.couponCode,function (err,result) {
                    if(err){
                        return callback(err,null);
                    }
                    if (!result || !result[0] || !result[0].c_code){
                        return callback("邀请码错误！",null);
                    }else{
                        return callback(null,data);
                    }
                });
            }else{
                return callback(null, data);
            }
        });
        // 1. 声明模型
        totalTasks.push(function (data, callback) {
            // 提取url的关键部分
            var k = activityUtil.getKeyValueOfUrl(param.url);
            var  entity = new YjxActUserProductModel({
                user_id:param.userId,
                act_id:param.activityId,
                type:10,
                unit:'分',
                url:param.url,
                tag:k,
                state:20, /*审核中*/
                desc:param.desc,
                c_code: param.couponCode
            });
            data.productEntity = entity;
            return callback(null, data);
        });
        // 2. 排重链接
        totalTasks.push(function (data, callback) {
            data.productEntity.haveSameProduct(function(error, repetition) {
                if (error) {
                    return callback(error);
                }
                if (Number(repetition) === 1) {
                    return callback(CODE.YJX_ACTIVITY_FAIL_SAME_PRODUCT);
                }
                return callback(error, data);
            });
        });
        // 3. 上限值判断
        totalTasks.push(function (data, callback) {
            //data.productEntity.reachProductCountLimit(function(error, reachLimit){
            //    if(error){
            //        return callback(error);
            //    }
            //    if(Number(reachLimit)===1){
            //        return callback(CODE.YJX_ACTIVITY_FAIL_REACH_PRODUCT_LIIT);
            //    }
            //    return callback(error, data);
            //});
            return callback(null, data);
        });
        // 4. 获取公司信息
        totalTasks.push(function (data, callback) {
            // 获取用户所在的合作公司的信息
            var entity2 = new YjxOrgRModel();
            entity2.getUserPartnerOrgInfo(param.userId, function(error, org){
                if(error){
                    return callback(error);
                }

                if(org &&org.length>0 && org[0].id){
                    data.productEntity.org_id = org[0].id;
                }
                return callback(error, data);
            });
        });
        // 5. 存入 db
        totalTasks.push(function (data, callback) {
            data.productEntity.saveToDB(function (error, aupId) {
                data.aupId = aupId;
                if (CONFIG.DEBUG === 1) console.log('new user product: ' + aupId);
                return callback(error, data);
            });
        });

        // 6. 爬取数据并更新至 db
        totalTasks.push(function (data, callback) {
            var url = 'http://127.0.0.1:3000' + '/yjx/v1/api4back/api4back/updateDouyinDataOfActivityProduct';
            // var url = 'http://114.55.29.218:3000' + '/yjx/v1/api4back/api4back/updateDouyinDataOfActivityProduct';
            var para = {
                activityId : param.activityId,
                productIds : '[' + data.aupId + ']'
            };
            superagent.get(url)
                .send(para)
                .end(function (error, res) {

                    if(error) {
                        console.log('update product '+data.aupId+' error : ' + error);
                    }
                    if(res) {
                        console.log('request res: ' + res.text)
                    }
                });
            return callback(null, data);
        });
        async.waterfall(totalTasks, function (error, data) {
            return callback(error, {});
        });
    };

    /**
     * 获取url的关键部分
     * */
    activityUtil.getKeyValueOfUrl = function( url){
        // 去掉头部 http:// https://
        // 去掉?后的参数
        var K1 = '://';
        var K2 = '?';

        var ret = url;
        var pos1 = url.indexOf(K1);
        var pos2 = url.indexOf(K2);
        if(pos1>=0 && pos2>=0){
            ret = url.substring(pos1+K1.length, pos2);
        }
        return ret;
    };



    return activityUtil;
})();

module.exports = activityUtil;